#pragma once
#include "Dispatcher.h"
#include <sys/select.h>
#include <string>

class SelectDispatcher : public Dispatcher
{
public:
    SelectDispatcher(EventLoop *evLoop);
    ~SelectDispatcher();
    // 添加
    int32_t add() override;
    // 删除
    int32_t remove() override;
    // 修改
    int32_t modify() override;
    // 事件检测 2s
    int32_t dispatch(int timeout = 2) override;

private:
    int32_t setFdSet();
    int32_t clearFdSet();
private:
    fd_set m_readfds;
    fd_set m_writefds;
    int32_t m_maxFd;
    const int m_maxNode = 1024;
};
